package com.jadefashion.health.resources;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.jadefashion.health.resources.ValidateCodeUtils;

public class SMSUtils {

//	public static void main(String[] args) {
//		sendCode("18817327122", String.valueOf(ValidateCodeUtils.generateValidateCode(6)));
////				ValidateCodeUtils.generateValidateCode(6));
//	}

	/**
	 *
	 * @param phoneNumber   用户手机号
	 * @param code   验证码数字
	 *               防盗刷   语音 + 图形验证码 + 滑块
	 */
	public static  void  sendCode(String phoneNumber,String code){
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GJbXZsfDisK7VkgMHJR", "5jHkhxaTnheMuhzvUckuVjdWroDJWb");
		IAcsClient client = new DefaultAcsClient(profile);
		CommonRequest request = new CommonRequest();
		request.setSysMethod(MethodType.POST);
		request.setSysDomain("dysmsapi.aliyuncs.com");
		request.setSysVersion("2017-05-25");
		request.setSysAction("SendSms");
		request.putQueryParameter("RegionId", "cn-hangzhou");
		request.putQueryParameter("PhoneNumbers", phoneNumber);
		request.putQueryParameter("SignName", "ABC医疗健康");
		request.putQueryParameter("TemplateCode", "SMS_198670307");
		request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
		try {
			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
		} catch (ServerException e) {
			e.printStackTrace();
		} catch (ClientException e) {
			e.printStackTrace();
		}
	}
}
